import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import {formatMessage} from './intl';
import * as dto from './DTO';
import stringify from 'Shared/utils/stringify';

const baseUrl = '/afterSales/api/v1';

const getListDesc = formatMessage({
    id: 'api.getList',
    defaultMessage: '查询列表'
});
const importTempDesc = formatMessage({
    id: 'api.message.importTempDesc',
    defaultMessage: '导出模板'
});

// 初始化查询
export const initQuery = () => request(`${baseUrl}/ui/monthInformation/init`, null, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery));

// 查询列表
export const getList = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/monthInformations?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

export const importTemp = () => request(`${baseUrl}/monthInformations/importTemp`, null, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, importTempDesc)).then(res => res.data);
